package indi.dos;

import indi.entity.*;

import java.util.*;
import java.util.Date;
import java.io.*;

public class WriteBook {

	public ArrayList<Book> books = new ArrayList<>();
	public ArrayList<BorrowBookLiscence> liscences = new ArrayList<>();
	
	
	WriteBook(){
		super();
		books.add(new Book("苏利•普吕多姆","《孤独与沉思》","经典","978-7-5682-0436-14"));
		books.add(new Book("欧内斯特•米歇尔•海明威","《老人与海》","经典","978-7-222-17584-6"));
		books.add(new Book("石黑一雄","《长日将尽》","经典","333"));
		books.add(new Book("威廉•萨默塞特•毛姆","《月亮和六便士》","经典","444"));
		books.add(new Book("刘慈欣","《三体》","经典","9787555011934"));
		books.add(new Book("莱曼•弗兰克·鲍姆","《绿野仙踪》","童书","978-7-5600-8293-6"));
		books.add(new Book("凯利•麦格尼格尔","《自控力》","心理","111"));
		books.add(new Book("Stephen Hawking","《时间简史》","物理","222"));
		//添加默认数据
		liscences.add(new BorrowBookLiscence(new Student("xiaorui", "CS")));
	
	}
	
	public static void writeBooks() throws Exception{
		// TODO Auto-generated method stub
		WriteBook w = new WriteBook();
		File file = new File("data//book.txt");
		if(null == file) {
			throw new Exception("无法输出书本！");
		}
		try (
				ObjectOutputStream output = new ObjectOutputStream(
						new FileOutputStream(file));
			){
			//分别输出每个书本
			for(Book e: w.books) {
				output.writeObject(e);
			}
		}catch(Exception e) {
			e.printStackTrace();
		}
		System.out.println("输出书本完成");
	}
	
	public static void writeLiscence() throws Exception{
	
		File file = new File("data//record.dat");
		if(null == file) {
			throw new Exception("无法创建记录文件！");
		}
		try (ObjectOutputStream output = new 
				ObjectOutputStream(new FileOutputStream(file))
				){
			//output.writeObject(liscences);
		}catch(Exception e) {
			e.printStackTrace();
		}
	}
	
	public static void main(String rgs[]) {
		
		try {
			//写入书本数据
			writeBooks();
			//写入记录数据
			//writeRecords();
		}catch(Exception e) {
			e.printStackTrace();
		}
		System.out.println("写入记录成功！");

	}
}
